/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SubsitemaAgenda;

import clienteSandraParada.Login;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListCellRenderer;

/**
 * Clase donde se encuentra la informacion de una cita
 * @author Mario
 */
public class PanelCita extends javax.swing.JPanel {

    private service.Cita cita;
    private Agenda agenda;
    private boolean cambioHora;
    public PanelCita(service.Cita cita, Agenda agenda) {
        initComponents();
        this.cita = cita;
        this.agenda = agenda;
        this.cambioHora=false;
        this.campoTelefono.getCelular().setEditable(false);
        cargarDatos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel7 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        campoObservacion = new javax.swing.JTextArea();
        campoHora = new javax.swing.JComboBox();
        campoMinuto = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        campoEstado = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        campoNumeroSesion = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        campoRut = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        campoTelefono = new componentes.Celular();
        campoPrograma = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        botonModificar = new javax.swing.JButton();
        botonEliminar = new javax.swing.JButton();

        jLabel7.setText("Programa Medico/ Bono Consulta:");

        jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextField2buscarPaciente(evt);
            }
        });

        jLabel3.setText("Observación");

        campoObservacion.setColumns(20);
        campoObservacion.setRows(5);
        jScrollPane2.setViewportView(campoObservacion);

        campoHora.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19" }));
        campoHora.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                campoHoraPropertyChange(evt);
            }
        });

        campoMinuto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55" }));
        campoMinuto.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                campoMinutoPropertyChange(evt);
            }
        });

        jLabel4.setText(":");

        jLabel2.setText("Desde:");

        campoEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No Confirmada", "Confirmada", "Atendida" }));

        jLabel8.setText("Estado:");

        jLabel9.setText("Número Sesión:");

        campoNumeroSesion.setEditable(false);

        jLabel11.setText("Rut Paciente:");

        campoRut.setEnabled(false);

        jLabel1.setText("Telefono");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        campoTelefono.setEnabled(false);

        campoPrograma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sin programa" }));
        campoPrograma.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                campoProgramaMouseEntered(evt);
            }
        });
        campoPrograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoProgramaActionPerformed(evt);
            }
        });
        campoPrograma.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                campoProgramaFocusGained(evt);
            }
        });

        jLabel10.setText("Programa");

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Protocolo.png"))); // NOI18N
        jButton1.setText("Crear programa");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        botonModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Edit2.png"))); // NOI18N
        botonModificar.setText("Modificar");
        botonModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonModificarActionPerformed(evt);
            }
        });

        botonEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Eliminar.png"))); // NOI18N
        botonEliminar.setText("Eliminar");
        botonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonModificar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonEliminar)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(botonModificar)
                    .addComponent(botonEliminar))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoRut, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel1))
                        .addGap(27, 27, 27)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(campoEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(campoTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(12, 12, 12)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(campoHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoMinuto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoNumeroSesion, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel11)
                                    .addComponent(campoRut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel8)
                                    .addComponent(campoEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(campoTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2)
                                    .addComponent(campoHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(campoMinuto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4))
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel10)
                                    .addComponent(campoPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel9)
                                    .addComponent(campoNumeroSesion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField2buscarPaciente(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField2buscarPaciente
        
    }//GEN-LAST:event_jTextField2buscarPaciente

    private void botonModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonModificarActionPerformed
        service.Privilegios p = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
        if(p.isModificarCita()){                         
            String valorAnterior = "Rut profesional:" + cita.getRutProfesional() + "\n" + "rut Paciente: " + cita.getRutPaciente()
                    + "\n" + "Fecha: " + cita.getFecha() + "\n" + "Desde hora: " + cita.getDesdeHora()
                    + "\n" + "Desde minuto: " + cita.getDesdeMinuto() + "\n" + "Número sesiones: " + cita.getNumeroSesion() + "\n" + "Observación: " + cita.getObservacion()
                    + "\n" + "Estado: " + cita.getEstado();
            cita.setEstado((String)campoEstado.getSelectedItem());
            cita.setDesdeHora(Integer.parseInt((String)campoHora.getSelectedItem()));
            cita.setDesdeMinuto(Integer.parseInt((String)campoMinuto.getSelectedItem()));                    
            cita.setNumeroSesion(Integer.parseInt(campoNumeroSesion.getText()));
            cita.setObservacion(campoObservacion.getText());
            String valorNuevo = "Rut profesional:" + cita.getRutProfesional() + "\n" + "rut Paciente: " + cita.getRutPaciente()
                    + "\n" + "Fecha: " + cita.getFecha() + "\n" + "Desde hora: " + cita.getDesdeHora()
                    + "\n" + "Desde minuto: " + cita.getDesdeMinuto() + "\n" + "Número sesiones: " + cita.getNumeroSesion() + "\n" + "Observación: " + cita.getObservacion()
                    + "\n" + "Estado: " + cita.getEstado();
            modificaPrograma();            
            modificarCita(cita); 
            actualizarAgendaModificar();
            agenda.campoMensajeria.setText("Cita modificada exitosamente");
            registrar(Login.getUser(),"Agenda","Modificó cita a profesional:" + cita.getRutProfesional()+"de paciente :"+cita.getRutPaciente(), valorAnterior, valorNuevo);
        }
        else
            JOptionPane.showMessageDialog(this,"No tiene permisos para esta acción, \n contacte al administrador para mas información");
    }//GEN-LAST:event_botonModificarActionPerformed

    private void botonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEliminarActionPerformed
        service.Privilegios p = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
        if(p.isEliminarCita()){
            int confirmado = JOptionPane.showConfirmDialog(this, "¿Esta seguro que desea eliminar la cita?");
            if (JOptionPane.OK_OPTION == confirmado){                                            
                cita.setVisible(false);
                modificarCita(cita);    
                actualizarAgendaEliminar();                
                agenda.campoMensajeria.setText("Cita eliminada exitosamente");
                String valorAnterior = "Rut profesional:" + cita.getRutProfesional() + "\n" + "rut Paciente: " + cita.getRutPaciente()
                    + "\n" + "Fecha: " + cita.getFecha() + "\n" + "Desde hora: " + cita.getDesdeHora()
                    + "\n" + "Desde minuto: " + cita.getDesdeMinuto() + "\n" + "Número sesiones: " + cita.getNumeroSesion() + "\n" + "Observación: " + cita.getObservacion()
                    + "\n" + "Estado: " + cita.getEstado();
                registrar(Login.getUser(), "Agenda", "Eliminó cita a profesional:" + cita.getRutProfesional()+"de paciente :"+cita.getRutPaciente(), valorAnterior, "");
            }
        }
         else
            JOptionPane.showMessageDialog(this,"No tiene permisos para esta acción, \n contacte al administrador para mas información");
    }//GEN-LAST:event_botonEliminarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        DialogoTipoPrograma d = new DialogoTipoPrograma(null, true,this.campoRut.getText());
        d.setAlwaysOnTop(true);
        d.setLocationRelativeTo(null);
        d.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void campoProgramaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_campoProgramaFocusGained
        cargarProgramas();
    }//GEN-LAST:event_campoProgramaFocusGained

    private void campoHoraPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_campoHoraPropertyChange
        cambioHora=true;
    }//GEN-LAST:event_campoHoraPropertyChange

    private void campoMinutoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_campoMinutoPropertyChange
        cambioHora=true;
    }//GEN-LAST:event_campoMinutoPropertyChange

    private void campoProgramaMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_campoProgramaMouseEntered
                
    }//GEN-LAST:event_campoProgramaMouseEntered

    private void campoProgramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoProgramaActionPerformed
        /*Object o = campoPrograma.getSelectedItem();
        if(o!=null){
            service.Cita c = (service.Cita) buscarCitaPorId(cita.getId());

            System.out.println(o);
            if(c.getTipoPrograma().equals("Sin programa")){                            
                if(o instanceof service.ProgramaMedicoFonasa){
                    service.ProgramaMedicoFonasa programa = (service.ProgramaMedicoFonasa) o;   
                    campoNumeroSesion.setText(programa.getCantidadCitasTotal()-programa.getCantidadCitas()+1+"");
                }
                else if(o instanceof service.ProgramaDipreca){
                    service.ProgramaDipreca programa = (service.ProgramaDipreca) o;
                    campoNumeroSesion.setText(programa.getCantidadCitasTotal()-programa.getCantidadCitas()+1+"");
                }
                else if(o instanceof service.ProgramaMedicoJeafosale){
                    service.ProgramaMedicoJeafosale programa = (service.ProgramaMedicoJeafosale) o;
                    campoNumeroSesion.setText(programa.getCantidadCitasTotal()-programa.getCantidadCitas()+1+"");
                }
                else
                    campoNumeroSesion.setText("0");
            }
            else if((c.getTipoPrograma().equals("FONASA") && o instanceof service.ProgramaMedicoFonasa )){
                service.ProgramaMedicoFonasa programa = (service.ProgramaMedicoFonasa) o;  
                System.out.println("FONASA "+ programa.getNumeroPrograma()+ " ID "+c.getIdPrograma() );                
                 if(!programa.getNumeroPrograma().equals(c.getIdPrograma()))                                  
                    campoNumeroSesion.setText(programa.getCantidadCitasTotal()-programa.getCantidadCitas()+1+"");
            }
            else if((c.getTipoPrograma().equals("DIPRECA") && o instanceof service.ProgramaDipreca )){
                service.ProgramaDipreca programa = (service.ProgramaDipreca) o;   
                 if(!programa.getNumeroPrograma().equals(c.getIdPrograma()))          
                    campoNumeroSesion.setText(programa.getCantidadCitasTotal()-programa.getCantidadCitas()+1+"");
            }
            else if((c.getTipoPrograma().equals("JEAFOSALE") && o instanceof service.ProgramaMedicoJeafosale )){
                service.ProgramaMedicoJeafosale programa = (service.ProgramaMedicoJeafosale) o;   
                if(!programa.getNumeroPrograma().equals(c.getIdPrograma()))          
                    campoNumeroSesion.setText(programa.getCantidadCitasTotal()-programa.getCantidadCitas()+1+"");
            }
            else if(o instanceof String)
                campoNumeroSesion.setText("0");
        }*/
            
    }//GEN-LAST:event_campoProgramaActionPerformed
    private void actualizarAgendaEliminar(){
        if(agenda.botonAgendaDiaria.isSelected()){
            Object o = agenda.dia.jTable1.getModel().getValueAt(agenda.dia.jTable1.getSelectedRow(), agenda.dia.jTable1.getSelectedColumn());
            if( o instanceof ArrayList) {
                ArrayList a = (ArrayList)o;
                a.remove(cita);
                agenda.dia.mostrarPanelCita(a);
                agenda.dia.jTable1.repaint();
                if(a.size()==0)
                    agenda.dia.jTable1.getModel().setValueAt(null, agenda.dia.jTable1.getSelectedRow(), agenda.dia.jTable1.getSelectedColumn());
            }
        }else{
            Object o = agenda.semana.jTable1.getModel().getValueAt(agenda.semana.jTable1.getSelectedRow(), agenda.semana.jTable1.getSelectedColumn());
            if( o instanceof ArrayList) {
                ArrayList a = (ArrayList)o;
                a.remove(cita);
                agenda.semana.mostrarPanelCita(a);
                agenda.semana.jTable1.repaint();
                if(a.size()==0)
                    agenda.semana.jTable1.getModel().setValueAt(null, agenda.semana.jTable1.getSelectedRow(), agenda.semana.jTable1.getSelectedColumn());
            }
        }                
    }
    private void actualizarAgendaModificar() {
        if(cita.getDesdeHora() == Integer.parseInt((String)campoHora.getSelectedItem()) && cita.getDesdeMinuto() == Integer.parseInt((String)campoMinuto.getSelectedItem()))
            cambioHora=false;
        else
            cambioHora=true;        
        if(agenda.botonAgendaDiaria.isSelected()){
            Object o = agenda.dia.jTable1.getModel().getValueAt(agenda.dia.jTable1.getSelectedRow(), agenda.dia.jTable1.getSelectedColumn());
            if( o instanceof ArrayList) {
                ArrayList<service.Cita> a = (ArrayList)o;
                if(cambioHora){
                    agenda.dia.llenarTabla();
                    agenda.dia.jTabbedPane1.remove(this);
                    cambioHora=false;
                }
                else{
                    for(int i = 0 ; i<a.size() ; i++){
                        if(a.get(i).equals(cita))
                            a.set(i, cita);
                    }
                    agenda.dia.mostrarPanelCita(a);
                }                
                agenda.dia.jTable1.repaint();
            }
        }else{
            Object o = agenda.semana.jTable1.getModel().getValueAt(agenda.semana.jTable1.getSelectedRow(), agenda.semana.jTable1.getSelectedColumn());
            if( o instanceof ArrayList) {
                ArrayList<service.Cita> a = (ArrayList)o;
                if(cambioHora){
                    agenda.semana.llenarTabla();
                    agenda.semana.jTabbedPane1.remove(this);
                    cambioHora=false;
                }
                else{
                    for(int i = 0 ; i<a.size() ; i++){
                        if(a.get(i).equals(cita))
                            a.set(i, cita);
                    }
                    agenda.semana.mostrarPanelCita(a);
                }                
                agenda.semana.jTable1.repaint();
            }
        }
    }
    
    public void modificaPrograma(){
        System.out.println("MODIFICAMOS PROGRAMA");
        System.out.println("ID p CITA " + cita.getIdPrograma()+ " TIPO p cita "+ cita.getTipoPrograma());
        Object o = campoPrograma.getSelectedItem();
        //instancia de STRING
        if(o instanceof String){            
            if(cita.getTipoPrograma().equals("FONASA")){                
                service.ProgramaMedicoFonasa f = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(cita.getIdPrograma());
                 f.setCantidadCitas(f.getCantidadCitas()+1);
                 f.setVisible(true);
                 modificarProgramaFonasa(f);
            }
            else if(cita.getTipoPrograma().equals("DIPRECA")){
                 service.ProgramaDipreca d = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(cita.getIdPrograma());
                 d.setCantidadCitas(d.getCantidadCitas()+1);                 
                 d.setVisible(true);
                 ModificarProgramaDipreca(d);
            }
            else if(cita.getTipoPrograma().equals("JEAFOSALE")){
                 service.ProgramaMedicoJeafosale j =  (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(cita.getIdPrograma());
                 j.setCantidadCitas(j.getCantidadCitas()+1);
                 j.setVisible(true);
                 modificarProgramaJeafosale(j);
            }
            cita.setTipoPrograma("Sin programa");
            cita.setIdPrograma("Sin programa");
            cita.setNumeroSesion(0);
        }        
        //instancia de FONASA
        if(o instanceof service.ProgramaMedicoFonasa){            
            service.ProgramaMedicoFonasa f = (service.ProgramaMedicoFonasa) o;
            if(cita.getTipoPrograma().equals("Sin programa")){                
                cita.setTipoPrograma("FONASA");
                cita.setIdPrograma(f.getNumeroPrograma());                
                f.setCantidadCitas(f.getCantidadCitas()-1);
                cita.setNumeroSesion(f.getCantidadCitasTotal()-f.getCantidadCitas());
                if(f.getCantidadCitas()==0)
                    f.setVisible(false);
                modificarProgramaFonasa(f); 
            }                
            if(cita.getTipoPrograma().equals("FONASA") && !cita.getIdPrograma().equals(f.getNumeroPrograma())){                
                service.ProgramaMedicoFonasa aux = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("FONASA");
                cita.setIdPrograma(f.getNumeroPrograma());                
                f.setCantidadCitas(f.getCantidadCitas()-1);
                cita.setNumeroSesion(f.getCantidadCitasTotal()-f.getCantidadCitas());
                if(f.getCantidadCitas()==0)
                    f.setVisible(false);
                modificarProgramaFonasa(f);
                modificarProgramaFonasa(aux);
            }
            if(cita.getTipoPrograma().equals("DIPRECA")){
                service.ProgramaDipreca aux = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("DIPRECA");
                cita.setIdPrograma(f.getNumeroPrograma());                
                f.setCantidadCitas(f.getCantidadCitas()-1);
                cita.setNumeroSesion(f.getCantidadCitasTotal()-f.getCantidadCitas());
                if(f.getCantidadCitas()==0)
                    f.setVisible(false);
                modificarProgramaFonasa(f);
                ModificarProgramaDipreca(aux);
            }
            if(cita.getTipoPrograma().equals("JEAFOSALE")){
                service.ProgramaMedicoJeafosale aux = (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("JEAFOSALE");
                cita.setIdPrograma(f.getNumeroPrograma());                
                f.setCantidadCitas(f.getCantidadCitas()-1);
                cita.setNumeroSesion(f.getCantidadCitasTotal()-f.getCantidadCitas());
                if(f.getCantidadCitas()==0)
                    f.setVisible(false);
                modificarProgramaFonasa(f);
                modificarProgramaJeafosale(aux);
            }            
        }
        //instancia DIPRECA
        else if(o instanceof service.ProgramaDipreca){
            service.ProgramaDipreca d = (service.ProgramaDipreca) o;
            if(cita.getTipoPrograma().equals("Sin programa")){                
                cita.setTipoPrograma("DIPRECA");
                cita.setIdPrograma(d.getNumeroPrograma());                
                d.setCantidadCitas(d.getCantidadCitas()-1);
                cita.setNumeroSesion(d.getCantidadCitasTotal()-d.getCantidadCitas());
                if(d.getCantidadCitas()==0)
                    d.setVisible(false);
                ModificarProgramaDipreca(d); 
            }
            if(cita.getTipoPrograma().equals("FONASA")){                
                service.ProgramaMedicoFonasa aux = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("FONASA");
                cita.setIdPrograma(d.getNumeroPrograma());                
                d.setCantidadCitas(d.getCantidadCitas()-1);
                cita.setNumeroSesion(d.getCantidadCitasTotal()-d.getCantidadCitas());
                if(d.getCantidadCitas()==0)
                    d.setVisible(false);
                ModificarProgramaDipreca(d);
                modificarProgramaFonasa(aux);
            }
            if(cita.getTipoPrograma().equals("DIPRECA") && !cita.getIdPrograma().equals(d.getNumeroPrograma())){
                service.ProgramaDipreca aux = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("DIPRECA");
                cita.setIdPrograma(d.getNumeroPrograma());                
                d.setCantidadCitas(d.getCantidadCitas()-1);
                cita.setNumeroSesion(d.getCantidadCitasTotal()-d.getCantidadCitas());
                if(d.getCantidadCitas()==0)
                    d.setVisible(false);
                ModificarProgramaDipreca(d);
                ModificarProgramaDipreca(aux);
            }
            if(cita.getTipoPrograma().equals("JEAFOSALE")){
                service.ProgramaMedicoJeafosale aux = (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("JEAFOSALE");
                cita.setIdPrograma(d.getNumeroPrograma());                
                d.setCantidadCitas(d.getCantidadCitas()-1);
                cita.setNumeroSesion(d.getCantidadCitasTotal()-d.getCantidadCitas());
                if(d.getCantidadCitas()==0)
                    d.setVisible(false);
                ModificarProgramaDipreca(d);
                modificarProgramaJeafosale(aux);
            }            
        }
        //instancia JEAFOSALE
        else if(o instanceof service.ProgramaMedicoJeafosale){
            service.ProgramaMedicoJeafosale j = (service.ProgramaMedicoJeafosale) o;
            if(cita.getTipoPrograma().equals("Sin programa")){                
                cita.setTipoPrograma("JEAFOSALE");
                cita.setIdPrograma(j.getNumeroPrograma());                
                j.setCantidadCitas(j.getCantidadCitas()-1);
                cita.setNumeroSesion(j.getCantidadCitasTotal()-j.getCantidadCitas());
                if(j.getCantidadCitas()==0)
                    j.setVisible(false);
                modificarProgramaJeafosale(j); 
            }
            if(cita.getTipoPrograma().equals("FONASA")){                
                service.ProgramaMedicoFonasa aux = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("FONASA");
                cita.setIdPrograma(j.getNumeroPrograma());                
                j.setCantidadCitas(j.getCantidadCitas()-1);
                cita.setNumeroSesion(j.getCantidadCitasTotal()-j.getCantidadCitas());
                if(j.getCantidadCitas()==0)
                    j.setVisible(false);
                modificarProgramaJeafosale(j);
                modificarProgramaFonasa(aux);
            }
            if(cita.getTipoPrograma().equals("DIPRECA")){
                service.ProgramaDipreca aux = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("DIPRECA");
                cita.setIdPrograma(j.getNumeroPrograma());                
                j.setCantidadCitas(j.getCantidadCitas()-1);
                cita.setNumeroSesion(j.getCantidadCitasTotal()-j.getCantidadCitas());
                if(j.getCantidadCitas()==0)
                    j.setVisible(false);
                modificarProgramaJeafosale(j);
                ModificarProgramaDipreca(aux);
            }
            if(cita.getTipoPrograma().equals("JEAFOSALE") && !cita.getIdPrograma().equals(j.getNumeroPrograma())){
                service.ProgramaMedicoJeafosale aux = (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(cita.getIdPrograma());
                aux.setCantidadCitas(aux.getCantidadCitas()+1);
                aux.setVisible(true);
                cita.setTipoPrograma("JEAFOSALE");
                cita.setIdPrograma(j.getNumeroPrograma());                
                j.setCantidadCitas(j.getCantidadCitas()-1);
                cita.setNumeroSesion(j.getCantidadCitasTotal()-j.getCantidadCitas());
                if(j.getCantidadCitas()==0)
                    j.setVisible(false);
                modificarProgramaJeafosale(j);
                modificarProgramaJeafosale(aux);
            }            
        }
        
        /*service.Cita c = (service.Cita) buscarCitaPorId(cita.getId());  
        System.out.println("tipo programa cita = " +c.getTipoPrograma() + " id programa " + c.getIdPrograma());
        Object o = campoPrograma.getSelectedItem();
        if(o instanceof String){                                           
            if(c.getTipoPrograma().equals("DIPRECA")){
                 service.ProgramaDipreca p = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
            }
            else if(c.getTipoPrograma().equals("FONASA")){
                 service.ProgramaMedicoFonasa p = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
            }
            else if(c.getTipoPrograma().equals("JEAFOSALE")){
                 service.ProgramaMedicoJeafosale p =  (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
            }
            cita.setIdPrograma("Sin programa");
            cita.setTipoPrograma("Sin programa");
        }      
        else if(o instanceof service.ProgramaDipreca){
            service.ProgramaDipreca d = (service.ProgramaDipreca)o;
            if(c.getTipoPrograma().equals("DIPRECA") && !d.getNumeroPrograma().equals(c.getIdPrograma())){
                 service.ProgramaDipreca p = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
            }
            else if(c.getTipoPrograma().equals("FONASA")){
                 service.ProgramaMedicoFonasa p = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
            }
            else if(c.getTipoPrograma().equals("JEAFOSALE")){
                 service.ProgramaMedicoJeafosale p =  (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
            }
            
            cita.setIdPrograma(d.getNumeroPrograma());
            cita.setTipoPrograma("DIPRECA");
        }
        else if(o instanceof service.ProgramaMedicoFonasa){
            System.out.println("o es instancia de programa medico fonasa");
            service.ProgramaMedicoFonasa f = (service.ProgramaMedicoFonasa)o;
            if(c.getTipoPrograma().equals("DIPRECA")){
                 service.ProgramaDipreca p = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
                 if(!p.isVisible())
                     p.setVisible(true);
            }
            else if(c.getTipoPrograma().equals("FONASA") && !f.getNumeroPrograma().equals(c.getIdPrograma())){
                System.out.println("c.getTipoPrograma().equals(\"FONASA\") && !f.getNumeroPrograma().equals(c.getIdPrograma())");
                 service.ProgramaMedicoFonasa p = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);  
                 if(!p.isVisible())
                     p.setVisible(true);
            }            
            else if(c.getTipoPrograma().equals("JEAFOSALE")){
                 service.ProgramaMedicoJeafosale p =  (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(c.getIdPrograma());
                 p.setCantidadCitas(p.getCantidadCitas()+1);
                 if(!p.isVisible())
                     p.setVisible(true);
            }
            if(!(c.getTipoPrograma().equals("FONASA") && f.getNumeroPrograma().equals(c.getIdPrograma()))){ 
                System.out.println("!(c.getTipoPrograma().equals(\"FONASA\") && f.getNumeroPrograma().equals(c.getIdPrograma()))");
                cita.setIdPrograma(f.getNumeroPrograma());
                cita.setTipoPrograma("FONASA");
                f.setCantidadCitas(f.getCantidadCitas()-1);
                if(f.getCantidadCitas()==0)
                    f.setVisible(false);
                modificarProgramaFonasa(f);            
            }
        }
        else if(o instanceof service.ProgramaMedicoJeafosale){
            service.ProgramaMedicoJeafosale p = (service.ProgramaMedicoJeafosale)o;
            cita.setIdPrograma(p.getNumeroPrograma());
            cita.setTipoPrograma("JEAFOSALE");
        }            */
    }
    
    public service.Cita getCita() {
        return cita;
    }

    public void setCita(service.Cita cita) {
        this.cita = cita;
    }
    private void cargarDatos() {
        campoRut.setText(cita.getRutPaciente());
        campoHora.setSelectedIndex(cita.getDesdeHora()-8);
        campoMinuto.setSelectedItem(cita.getDesdeMinuto()+"");                                
        campoEstado.setSelectedItem(cita.getEstado());
        String celular = ((service.Paciente)cargarPaciente(cita.getRutPaciente())).getCelular();
        String telefono = ((service.Paciente)cargarPaciente(cita.getRutPaciente())).getTelefono();
        String contacto = "";
        System.out.println("celular "+celular+" telefono "+telefono);
        if(!celular.equals("") && !telefono.equals(""))
            contacto = celular+"/"+telefono;
        else if(!celular.equals(""))
            contacto = celular;
        else if(!telefono.equals(""))
            contacto = telefono;
        campoTelefono.getCelular().setText(contacto);
        campoNumeroSesion.setText(cita.getNumeroSesion()+"");               
        campoObservacion.setText(cita.getObservacion()); 
        cargarProgramas();
    }
    private void cargarProgramas(){
        campoPrograma.removeAllItems();
        campoPrograma.addItem("Sin programa");     
        List<service.ProgramaMedicoFonasa> f = buscarProgramasFonasaDePaciente(cita.getRutPaciente());
        for(int i = 0 ; i<f.size() ; i++)
            campoPrograma.addItem(f.get(i));
        List<service.ProgramaDipreca> d = buscarProgramasDiprecaDePaciente(cita.getRutPaciente());
        for(int i = 0 ; i<d.size() ; i++)
            campoPrograma.addItem(d.get(i));
        List<service.ProgramaMedicoJeafosale> j = buscarProgramasJeafosaleDePaciente(cita.getRutPaciente());
        for(int i = 0 ; i<j.size() ; i++)
            campoPrograma.addItem(j.get(i));        
        
        if(cita.getTipoPrograma().equals("FONASA")){   
            service.ProgramaMedicoFonasa programa = (service.ProgramaMedicoFonasa) cargarProgramaFonasaPorNumero(cita.getIdPrograma());
            if(!programa.isVisible())
                campoPrograma.addItem(programa);
            seleccionarPrograma(programa);
        }if(cita.getTipoPrograma().equals("DIPRECA")){   
            service.ProgramaDipreca programa = (service.ProgramaDipreca) cargarProgramaMedicoDipreca(cita.getIdPrograma());
            if(!programa.isVisible())
                campoPrograma.addItem(programa);
            seleccionarPrograma(programa);
        }if(cita.getTipoPrograma().equals("JEAFOSALE")){   
            service.ProgramaMedicoJeafosale programa = (service.ProgramaMedicoJeafosale) cargarProgramaMedicoJeafosale(cita.getIdPrograma());
            if(!programa.isVisible())
                campoPrograma.addItem(programa);
            seleccionarPrograma(programa);
        }
        campoPrograma.setRenderer(new RenderJCombobox());
    }    
    public void seleccionarPrograma(Object o){
        for(int i = 0 ; i<campoPrograma.getItemCount(); i++){
            if(o instanceof service.ProgramaMedicoFonasa && campoPrograma.getItemAt(i) instanceof service.ProgramaMedicoFonasa){
                service.ProgramaMedicoFonasa aux1 = (service.ProgramaMedicoFonasa) o;
                service.ProgramaMedicoFonasa aux2 = (service.ProgramaMedicoFonasa) campoPrograma.getItemAt(i);
                if(aux1.getNumeroPrograma().equals(aux2.getNumeroPrograma())){
                    campoPrograma.setSelectedIndex(i);
                }
                    
            }
            else if(o instanceof service.ProgramaDipreca && campoPrograma.getItemAt(i) instanceof service.ProgramaDipreca){
                service.ProgramaDipreca aux1 = (service.ProgramaDipreca) o;
                service.ProgramaDipreca aux2 = (service.ProgramaDipreca) campoPrograma.getItemAt(i);
                if(aux1.getNumeroPrograma().equals(aux2.getNumeroPrograma())){
                    campoPrograma.setSelectedIndex(i);
                }
            }
            else if(o instanceof service.ProgramaMedicoJeafosale && campoPrograma.getItemAt(i) instanceof service.ProgramaMedicoJeafosale){
                service.ProgramaMedicoJeafosale aux1 = (service.ProgramaMedicoJeafosale) o;
                service.ProgramaMedicoJeafosale aux2 = (service.ProgramaMedicoJeafosale) campoPrograma.getItemAt(i);
                if(aux1.getNumeroPrograma().equals(aux2.getNumeroPrograma())){
                    campoPrograma.setSelectedIndex(i);
                }
            }
        }
    
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonEliminar;
    private javax.swing.JButton botonModificar;
    public javax.swing.JComboBox campoEstado;
    public javax.swing.JComboBox campoHora;
    public javax.swing.JComboBox campoMinuto;
    public javax.swing.JTextField campoNumeroSesion;
    public javax.swing.JTextArea campoObservacion;
    public javax.swing.JComboBox campoPrograma;
    public javax.swing.JTextField campoRut;
    public componentes.Celular campoTelefono;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables

    private static boolean modificarCita(service.Cita arg0) {
        service.AgendaWS_Service service = new service.AgendaWS_Service();
        service.AgendaWS port = service.getAgendaWSPort();
        return port.modificarCita(arg0);
    }

    
    class RenderJCombobox implements ListCellRenderer{        
        DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
        @Override
        public Component getListCellRendererComponent(JList jlist, Object e, int i, boolean bln, boolean bln1) {            
            JLabel label= (JLabel) defaultRenderer.getListCellRendererComponent(jlist, e, i, bln, bln1);
            if(e instanceof String){            
                label.setText((String)e);
            }
            if(e instanceof service.ProgramaDipreca){            
                label.setText(((service.ProgramaDipreca)e).getNumeroPrograma()+" - "+"DIPRECA");
            }
            if(e instanceof service.ProgramaMedicoFonasa){            
                label.setText(((service.ProgramaMedicoFonasa)e).getNumeroPrograma()+" - "+"FONASA");
            }
            if(e instanceof service.ProgramaMedicoJeafosale){
                label.setText(((service.ProgramaMedicoJeafosale)e).getNumeroPrograma()+" - "+"JEAFOSALE");
            }
            
            return label;
        }
    }

    

    private static Object cargarPrivilegios(java.lang.String rut) {
        service.PrivilegiosWS_Service service = new service.PrivilegiosWS_Service();
        service.PrivilegiosWS port = service.getPrivilegiosWSPort();
        return port.cargarPrivilegios(rut);
    }

    private static Object cargarPaciente(java.lang.String rut) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();
        return port.cargarPaciente(rut);
    }       

    private static Long registrar(service.Usuario usuario, java.lang.String modulo, java.lang.String accion, java.lang.String valorAnterior, java.lang.String valorNuevo) {
        service.BitacoraWSService service = new service.BitacoraWSService();
        service.BitacoraWS port = service.getBitacoraWSPort();
        return port.registrar(usuario, modulo, accion, valorAnterior, valorNuevo);
    }

    private static Object buscarCitaPorId(java.lang.Long id) {
        service.AgendaWS_Service service = new service.AgendaWS_Service();
        service.AgendaWS port = service.getAgendaWSPort();
        return port.buscarCitaPorId(id);
    }
    private static java.util.List<service.ProgramaDipreca> buscarProgramasDiprecaDePaciente(java.lang.String rutPaciente) {
        service.AgendaWS_Service service = new service.AgendaWS_Service();
        service.AgendaWS port = service.getAgendaWSPort();
        return port.buscarProgramasDiprecaDePaciente(rutPaciente);
    }

    private static java.util.List<service.ProgramaMedicoFonasa> buscarProgramasFonasaDePaciente(java.lang.String rutPaciente) {
        service.AgendaWS_Service service = new service.AgendaWS_Service();
        service.AgendaWS port = service.getAgendaWSPort();
        return port.buscarProgramasFonasaDePaciente(rutPaciente);
    }

    private static java.util.List<service.ProgramaMedicoJeafosale> buscarProgramasJeafosaleDePaciente(java.lang.String rutPaciente) {
        service.AgendaWS_Service service = new service.AgendaWS_Service();
        service.AgendaWS port = service.getAgendaWSPort();
        return port.buscarProgramasJeafosaleDePaciente(rutPaciente);
    }

    private static boolean modificarProgramaJeafosale(service.ProgramaMedicoJeafosale programaDipreca) {
        service.ProgramaJeafosaleWSService service = new service.ProgramaJeafosaleWSService();
        service.ProgramaJeafosaleWS port = service.getProgramaJeafosaleWSPort();
        return port.editarProgramaJeafosale(programaDipreca);
    }

    
    
    private static boolean ModificarProgramaDipreca(service.ProgramaDipreca programaDipreca) {
        service.ProgramaDiprecaWSService service = new service.ProgramaDiprecaWSService();
        service.ProgramaDiprecaWS port = service.getProgramaDiprecaWSPort();
        return port.editarProgramaDipreca(programaDipreca);
    }
    

    private static Object cargarProgramaMedicoJeafosale(java.lang.String numero) {
        service.ProgramaJeafosaleWSService service = new service.ProgramaJeafosaleWSService();
        service.ProgramaJeafosaleWS port = service.getProgramaJeafosaleWSPort();
        return port.obtenerProgramaJeafosale(numero);
    }

    private static Object cargarProgramaMedicoDipreca(java.lang.String numero) {
        service.ProgramaDiprecaWSService service = new service.ProgramaDiprecaWSService();
        service.ProgramaDiprecaWS port = service.getProgramaDiprecaWSPort();
        return port.obtenerProgramaDipreca(numero);
    }   

    private static Object cargarProgramaFonasaPorNumero(java.lang.String id) {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.cargarProgramaFonasaPorNumero(id);
    }

    private static boolean modificarProgramaFonasa(service.ProgramaMedicoFonasa programaMedico) {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.modificarProgramaFonasa(programaMedico);
    }

    
}
